import java.util.Stack;

public class Leet388 {
    public static void main(String[] args) {
        Leet388 l = new Leet388();
        System.out.println(l.lengthLongestPath("dir\n\t        file.txt\n\tfile2.txt"));
    }
    public int lengthLongestPath(String input) {
        if (!input.contains("."))
            return 0;
        int max = 0;
        int num = 0;
        int ceng = 0;
        Stack<Integer> stack = new Stack<>();
        while (true){
            int index = input.indexOf('\n');
            if (index<0)
                break;
            String temp = input.substring(0,index);
            input = input.substring(index+1);
            stack.push(index);
            num +=index;
            if (temp.contains("."))
                max = Math.max(max,num);
            num++;
            int tc = 0;
            while (true){
                if (input.charAt(0)=='\t'){
                    input = input.substring(1);
                    tc++;
                }else break;
            }
            int te = tc;
            while (ceng>=tc&&!stack.isEmpty()){
                num-=stack.pop()+1;
                tc++;
            }
            ceng = te;
        }
        max = Math.max(max,num+input.length());
        return max;
    }
}
